package com.lizhao.win007com.crawler.webapi.mapper;

import com.lizhao.win007com.commons.pojo.info.model.MonitorEasyRealTimeInfo;
import com.lizhao.win007com.commons.pojo.info.model.MonitorEasyRealTimeTotalInfo;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;


@Repository
public interface CrawlerMapper {
    @Select("SELECT * FROM `monitor-realtime` WHERE pageid=#{pageid};")
    MonitorEasyRealTimeInfo findRealTimeByPageId(@Param("pageid") Integer pageid);

    // 统计实时赔型总数
    @Select("SELECT * FROM `monitor-realtime-total` WHERE pageid=#{pageid} AND ptype=#{ptype} AND pname=#{pname};")
    MonitorEasyRealTimeTotalInfo findRealTimeTotal(MonitorEasyRealTimeTotalInfo monitorEasyRealTimeTotalInfo);

    // 添加今日赛事数据
    @Insert("INSERT INTO `monitor-realtime` (id,leaguetype,pageid,matchdatetime,hometeam,guestteam,r1,r2,eh,eg," +
            "hh,hg,updatestatus) VALUES (NULL,#{leaguetype},#{pageid},#{matchdatetime},#{hometeam},#{guestteam}," +
            "#{r1},#{r2},#{eh},#{eg},#{hh},#{hg},0);")
    void addRealTimeInfo(MonitorEasyRealTimeInfo monitorEasyRealTimeInfo);

    // 添加实时赔型总数
    @Insert("INSERT INTO `monitor-realtime-total` VALUES (NULL,#{pageid},#{ptype},#{pname},#{total});")
    void addRealTimeTotalInfo(MonitorEasyRealTimeTotalInfo monitorEasyRealTimeTotalInfo);

    // 修改今日数据
    @Update("UPDATE `monitor-realtime` SET avg3=#{avg3},avg1=#{avg1},avg0=#{avg0},realtime3=#{realtime3}," +
            "realtime1=#{realtime1},realtime0=#{realtime0} WHERE pageid=#{pageid};")
    void updateRealTimeInfo(MonitorEasyRealTimeInfo monitorEasyRealTimeInfo);

    @Update("UPDATE `monitor-realtime-total` SET total=#{total} WHERE pageid=#{pageid} AND ptype=#{ptype} AND pname=" +
            "#{pname}")
    void updateRealTimeTotalInfo(MonitorEasyRealTimeTotalInfo monitorEasyRealTimeTotalInfo);

    // 获取所有试试数据表的赛事

    @Select("SELECT * FROM `monitor-realtime` ORDER BY matchdatetime")
    List<MonitorEasyRealTimeInfo> findAllRealTimeInfo();

    // 通过pageid获取统计表的数据
    @Select("SELECT * FROM `monitor-realtime-total` WHERE pageid=#{pageid}")
    List<MonitorEasyRealTimeTotalInfo> findRealTimeTotalById(@Param("pageid") Integer pageid);

    // 通过pageid获取统计表赔型总数
    @Select("SELECT SUM(total) total FROM `monitor-realtime-total` WHERE pageid=#{pageid};")
    int findRealTimeSumInfo(@Param("pageid") Integer pageid);

    // 通过pageid修改赔型
    @Update("UPDATE `monitor-realtime` SET eh=#{eh},eg=#{eg},hh=#{hh},hg=#{hg},isbig51=#{isbig51},isbig90=#{isbig90}," +
            "avgtag=#{avgtag} WHERE pageid=#{pageid};")
    void updateRealInfo(MonitorEasyRealTimeInfo monitorEasyRealTimeInfo);
}
